﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using 无线打分网站.webAPI;
using WFNetLib;
using System.Web.Security;

namespace 无线打分网站.Manage
{
    public partial class TeacherManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HiddenField1.Value == null || HiddenField1.Value == "1")
            {
                HiddenField1.Value = "";
                Bind();
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string id = e.Row.Cells[0].Text;
                ((Button)e.Row.Cells[3].Controls[0]).Attributes.Add("onclick", "if(!showdialog('" + id + "')) return");
                ((Button)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "if(!window.confirm('确定删除此教师')) return;");
                e.Row.Cells[2].Text = Server.HtmlDecode(e.Row.Cells[2].Text);
                //e.Row.Cells[3].Attributes.Add("style", "word-break :break-all ; word-wrap:break-word");
            }
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string id = GridView1.Rows[e.RowIndex].Cells[0].Text;
            UserExData ed;
            ed = UserExDataDBOption.GetUserExData(new Guid(id));
            UserExDataDBOption.Delete(ed);
            Membership.DeleteUser(ed.Name,true);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "", " <script lanuage=javascript>alert('删除成功');</script>");
            Bind();
        }
        void Bind()
        {
            DataTable dt = UserExDataDBOption.DataTableSelect();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string exs = dt.Rows[i]["ExperimentID"].ToString();
                string Experiment="";
                string[] exss=exs.Split(';');
                foreach (string ex in exss)
                {
                    if (string.IsNullOrEmpty(ex))
                        continue;
                    ExperimentData ed = ExperimentDataDBOption.GetExperimentData(new Guid(ex));
                    Experiment += ed.Name + "<br/>";
                }
                Experiment = Experiment.Substring(0, Experiment.Length - 5);
                dt.Rows[i]["ExperimentID"] = Experiment;
            }
            GridView1.Columns[0].Visible = true;
            GridView1.DataSource = dt;
            GridView1.DataBind();
            GridView1.Columns[0].Visible = false;
        }
    }
}